﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media;


namespace TMI85303.UI.UserControls
{
    public class LedIndicator : Control
    {
        static LedIndicator()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(LedIndicator), new FrameworkPropertyMetadata(typeof(LedIndicator)));
        }

        public static readonly DependencyProperty LedStatusProperty = DependencyProperty.Register(
    "LedStatus", typeof(bool), typeof(LedIndicator), new PropertyMetadata(false, OnLedStatusChanged));

        public bool LedStatus
        {
            get { return (bool)GetValue(LedStatusProperty); }
            set { SetValue(LedStatusProperty, value); }
        }

        private static void OnLedStatusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var control = (LedIndicator)d;
            control.LedColor = control.LedStatus ? control.LedTrueColor : control.LedFalseColor;
        }

        public static readonly DependencyProperty LedColorProperty =
            DependencyProperty.Register("LedColor", typeof(Brush), typeof(LedIndicator), new PropertyMetadata(Brushes.Red));

        public Brush LedColor
        {
            get { return (Brush)GetValue(LedColorProperty); }
            private set { SetValue(LedColorProperty, value); }
        }

        public static readonly DependencyProperty LedTrueColorProperty = DependencyProperty.Register(
            "LedTrueColor", typeof(Brush), typeof(LedIndicator), new PropertyMetadata(Brushes.Green, OnLedTrueColorChanged));

        public Brush LedTrueColor
        {
            get { return (Brush)GetValue(LedTrueColorProperty); }
            set { SetValue(LedTrueColorProperty, value); }
        }

        private static void OnLedTrueColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var control = (LedIndicator)d;
            if (control.LedStatus) control.LedColor = control.LedTrueColor;
        }

        public static readonly DependencyProperty LedFalseColorProperty = DependencyProperty.Register(
            "LedFalseColor", typeof(Brush), typeof(LedIndicator), new PropertyMetadata(Brushes.Red, OnLedFalseColorChanged));

        public Brush LedFalseColor
        {
            get { return (Brush)GetValue(LedFalseColorProperty); }
            set { SetValue(LedFalseColorProperty, value); }
        }

        private static void OnLedFalseColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var control = (LedIndicator)d;
            if (!control.LedStatus) control.LedColor = control.LedFalseColor;
        }

    }
}
